package com.lonely.web.controller.outsource;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.StatusInfo;
import com.lonely.common.core.domain.api.R;
import com.lonely.product.domain.dto.sewing.QueryOrderSewingPageDTO;
import com.lonely.product.domain.dto.sewing.SewingCompletedDTO;
import com.lonely.product.domain.dto.sewing.StartSewingDTO;
import com.lonely.product.domain.vo.sewing.QueryOrderSewingPageVO;
import com.lonely.product.service.IOrderSewingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黄志标
 * @date: 2025/7/24 14:02
 * @description: 外发车缝请求处理器
 */
@RestController
@RequestMapping("/outsourceManager/outsourceSewing")
@Api(tags = "外发管理/外发车缝管理")
public class OutsourceSewingController {

    @Autowired
    private IOrderSewingService orderSewingService;


    /**
     * 外发车缝分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "外发车缝分页查询")
    public R<Page<QueryOrderSewingPageVO>> outsourcePage(@RequestBody @Validated QueryOrderSewingPageDTO queryDto) {
        return R.data(this.orderSewingService.outsourcePage(queryDto));
    }

    /**
     * 获取外发车缝状态信息
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/getStatusInfo")
    public R<List<StatusInfo>> getOutsourceStatusInfo(@RequestBody @Validated QueryOrderSewingPageDTO queryDto) {
        return R.data(this.orderSewingService.getOutsourceStatusInfo(queryDto));
    }

    /**
     * 获取默认的开始车缝数
     *
     * @param sewingId
     * @return
     */
    @GetMapping("/getDefaultStartSewingQuantity/{sewingId}")
    public R<String> getDefaultStartSewingQuantity(@PathVariable("sewingId") Long sewingId) {
        return R.data(this.orderSewingService.getDefaultStartSewingQuantity(sewingId));
    }

    /**
     * 开始车缝
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/startSewing")
    @SaCheckPermission("outsource:outsourceSewing:startSewing")
    public R<Boolean> startSewing(@RequestBody @Validated StartSewingDTO requestDto) {
        this.orderSewingService.startSewing(requestDto);
        return R.status(true);
    }

    /**
     * 获取默认的车缝完工数
     *
     * @param sewingId
     * @return
     */
    @GetMapping("/getDefaultCompletedSewingQuantity/{sewingId}")
    public R<String> getDefaultCompletedSewingQuantity(@PathVariable("sewingId") Long sewingId) {
        return R.data(this.orderSewingService.getDefaultCompletedSewingQuantity(sewingId));
    }

    /**
     * 车缝完工
     *
     * @param requestDto
     * @return
     */
    @PostMapping("/sewingCompleted")
    @SaCheckPermission("outsource:outsourceSewing:sewingCompleted")
    public R<Boolean> sewingCompleted(@RequestBody @Validated SewingCompletedDTO requestDto) {
        this.orderSewingService.sewingCompleted(requestDto);
        return R.status(true);
    }

}
